package main

import (
	"IrisService/controllers"
	"IrisService/datasource"
	"IrisService/models"

	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/middleware/logger"
	"github.com/kataras/iris/v12/middleware/recover"
	"github.com/kataras/iris/v12/mvc"
)

func main() {
	app := iris.New()
	app.Use(recover.New())
	app.Use(logger.New())

	dsHelper := datasource.NewDSHelper()
	dsHelper.LoadConfig("conf/test.json")

	db := dsHelper.GetDB()
	gEntityController := controllers.NewGEntityController(db)
	entryController := controllers.NewEntryController(db)
	changeLog := controllers.NewChangeLog(db)
	whisper := controllers.NewWhisper()

	mvc.New(app.Party("/GEntity")).Handle(gEntityController)
	mvc.New(app.Party("/Whisper")).Handle(whisper)
	mvc.New(app.Party("/ChangeLog")).Handle(changeLog)
	mvc.New(app.Party("/Entry")).Handle(entryController)
	app.Get("/", func(ctx iris.Context) {
		ctx.JSON(models.GenIndex("Home"))
	})

	app.Run(iris.Addr(":8080"))
}

/*
userController := bak.NewUserController()
whisper := bak.NewWhisper()
app.PartyFunc("/user", userController.Gen)
app.PartyFunc("/whisper", whisper.Gen)
*/
